home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / tools / cdfwalk1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  37.6 KB  |  1,412 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                        CDFwalk.  Part 1 or 2.
  4. *
  5. *  Version 2.0, 4-Mar-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  25-Jul-91, H Leckner    Original version (for CDF V2.1).
  10. *   V1.0a  5-Aug-91, J Love    Fixed value input.
  11. *   V1.1  20-Sep-91, J Love    Modified for IBM-PC port.
  12. *   V1.2  11-Oct-91, H Leckner    Changed for IBM-RS6000 port.
  13. *   V1.3  18-Oct-91, H Leckner    More changes for IBM-RS6000 port (and fixed
  14. *                variable name field).
  15. *   V1.3a 22-Oct-91, J Love    Got the right version this time.
  16. *   V2.0   4-Mar-92, J Love    IBM PC port.  CDF V2.2.
  17. *
  18. ******************************************************************************/
  19.  
  20. #include "wfl.h"
  21.  
  22. #include <stdio.h>
  23. #include <math.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26.  
  27. #if defined(unix)
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. extern char *getenv();
  31. #else
  32. #if defined (vms)
  33. #include <descrip.h>
  34. #else
  35. #if defined(__MSDOS__)
  36. #include <dos.h>
  37. #endif
  38. #endif
  39. #endif
  40. #define CDFWALK 1
  41. #include "cdfdist.h"
  42. #include "kb_def.h"
  43. #include "utility.h"
  44. #include "cdfwalk.h"
  45.  
  46. #if defined(vms)
  47. main (argc, argv)
  48. #else
  49. void main (argc, argv)
  50. #endif
  51. int        argc;
  52. char        *argv[];
  53. {
  54. static struct    CDF_struct CDF;
  55. static struct    GLOBAL_struct    screen;
  56. struct        variable_struct *variables;
  57. struct        vid_struct    *VAR_display;
  58. union            mixed         *data_values;
  59. CDFstatus    rcode;
  60. long int    i;
  61. long int    CDF_is_OPEN = FALSE;
  62. static char    open_mes[] = "Opening CDF...";
  63. /*FILE        *fptr;*/
  64. long int    field_num;
  65. long int     exit_code;
  66. int        tcode;
  67. long int    cdf_input = MANUAL;
  68. char        temp[CDF_PATHNAME_LEN];
  69. char        help_file_name[80];
  70. #if defined(unix) || defined(__MSDOS__)
  71. char *s;
  72. #endif
  73. QOP *qop;
  74. static char *validQuals[] = { NULL };
  75. for (i=0; i < CDF_NAME_LENGTH; i++)CDF.CDF_name[i] = '\0';
  76.  
  77. qop = Qop (argc, argv, validQuals, NULL);
  78. if (qop == NULL) ExitBAD;
  79. switch (qop->Nparms) {
  80.   case 0:
  81.      strcpy(CDF.CDF_name, default_name);
  82.   break;
  83.   case 1:
  84.       cdf_input = AUTO;
  85.       strcpy(CDF.CDF_name, qop->parms[0]);
  86.       strcpy(temp, qop->parms[0]);
  87.       strcat(temp,".cdf");
  88.       if(!IsReg(temp))cdf_input = DIRECTORY;
  89.   break;
  90.   default:
  91.     printf ("Too many parameters.\n");
  92.     ExitBAD;
  93. }
  94. field_num = 1;
  95. rcode = init_var_display(&VAR_display);
  96. if(rcode != 0)ExitBAD;
  97. CDFWALK_open_screen(&screen);
  98.  
  99. HELP_ptr = NULL;
  100. #if defined(unix)
  101. s = getenv("CDF_HELP");
  102. if(s)
  103.   {
  104.   strcpy(help_file_name, s);
  105.   strcat(help_file_name, "/cdfwalk.hlp");
  106.   }
  107. else
  108.   strcpy(help_file_name, "../help/cdfwalk.hlp");
  109. #endif
  110. #ifdef vms
  111. strcpy(help_file_name,"CDF$HELP:cdfwalk.hlp");
  112. #endif
  113. #if defined(__MSDOS__)
  114. s = getenv("CDF_HELP");
  115. if(s)
  116.   {
  117.   strcpy(help_file_name, s);
  118.   strcat(help_file_name, "\\cdfwalk.hlp");
  119.   }
  120. else
  121.    strcpy(help_file_name, ".\\cdfwalk.hlp");
  122. HELP_ptr = fopen(help_file_name, "r");
  123. if(HELP_ptr == NULL)
  124.    {
  125.    strcpy(help_file_name, "c:\\cdf22\\help\\cdfwalk.hlp");
  126.    HELP_ptr = fopen(help_file_name, "r");
  127.    }
  128. #endif
  129.  
  130. variables = NULL;
  131. data_values = NULL;
  132.  
  133. while(field_num != EXIT)
  134.  {
  135.  switch (field_num)
  136.       {
  137.       case CDF_FIELD:
  138.        CDFWALK_put_selection(screen.CDF_vid, CDF_display,
  139.        CDFNAME_ELEMENT_NUM-1, CDF.CDF_name, CDF_NAME_LENGTH-COL_OFFSET,
  140.                  REVERSE);
  141.        if(cdf_input != AUTO)
  142.           tcode = CDFWALK_CDF_name(&screen, &CDF, &field_num, &cdf_input);
  143.        else
  144.           {
  145.           field_num = WALK_FIELD;
  146.           tcode = CONTINUE;
  147.           }
  148.        if(tcode != QUIT && field_num != EXIT && strlen(CDF.CDF_name) > 0)
  149.           {
  150.           if(CDF_is_OPEN)
  151.          {
  152.          CDFWALK_close(&CDF, variables);
  153.          free(data_values);
  154.          }
  155.           CDFWALK_put_message(screen.MES_vid, open_mes, NOBELL, BLINK,
  156.         NOPAUSE);
  157.           for (i=0; i < CDF_MAX_DIMS; i++)
  158.            CDF.dim_var_num[i] = NOTTHERE;
  159.           rcode = CDFWALK_open(&CDF, &variables, &data_values);
  160.           cdf_input = MANUAL;
  161.           if(rcode < CDF_OK || rcode == NODATA)
  162.             {
  163.             exit_code = print_error(&screen, rcode);
  164.             if(exit_code == NOCONTINUE)field_num = CDF_FIELD;
  165.             CDF_is_OPEN = FALSE;
  166.             }
  167.           else
  168.             {
  169.             CDF_is_OPEN = TRUE;
  170.             CDFWALK_CDF_info(&screen, &CDF, CDF_display);
  171.             CDFWALK_clear_row(screen.VAR_vid, VAR_display, 1, 54,
  172.             VAR_COLUMNS-COL_OFFSET);
  173.             CDFWALK_clear_row(screen.MES_vid, MES_display, 1, 1,
  174.             MES_COLUMNS-COL_OFFSET);
  175.             }
  176.           }
  177.        break;
  178.       case WALK_FIELD:
  179.        CDFWALK_list(&screen, &CDF, variables, VAR_display, data_values,
  180.             &field_num);
  181.        break;
  182.       case HELP_FIELD:
  183.        CDFWALK_help(&screen);
  184.        CDFWALK_field_menu(&screen, &field_num);
  185.       }
  186.   }
  187. if(HELP_ptr != NULL)fclose(HELP_ptr);
  188. free(VAR_display);
  189. if(CDF_is_OPEN)CDFWALK_close(&CDF, variables);
  190. CDFWALK_close_screen();
  191. Exit;
  192. }
  193. long int print_error(screen, rcode)
  194. struct            GLOBAL_struct    *screen;
  195. CDFstatus    rcode;
  196. {
  197. long int    exit_code;
  198. char    error_mes[CDF_ERRTEXT_LEN];
  199. if(rcode == NODATA)
  200.    {
  201.    exit_code = NOCONTINUE;
  202.    strcpy(error_mes, "This CDF contains no records");
  203.    }
  204. else
  205.    {
  206.    if(rcode < CDF_WARN)
  207.     exit_code = NOCONTINUE;
  208.    else if(rcode < CDF_OK)
  209.     exit_code = CONTINUE;
  210.    else if(rcode != CDF_OK)
  211.     exit_code = CONTINUE;
  212. /*
  213. Get the error message
  214. */
  215.    CDFerror(rcode, error_mes);
  216.    }
  217. /*
  218. Print the message
  219. */
  220. CDFWALK_put_message(S.MES_vid, error_mes, RINGBELL, NORMAL, PAUSE);
  221. return(exit_code);
  222. }
  223. int alloc_all_dim(ptr, num_vars, num_dims)
  224. long int    ***ptr;
  225. long int    num_vars;
  226. long int    num_dims;
  227. {
  228. long int    i;
  229. long int    num;
  230.  
  231. if((*ptr = (long int **)
  232.     malloc((CDF_MAX_DIMS+1) * sizeof(long int *))) == NULL)
  233.     return(-1);
  234. else
  235.     {
  236.     num = num_vars > num_dims ? num_vars+1 : num_dims+1;
  237.     for(i=0; i<num; i++)
  238.        {
  239.        if(((*ptr)[i] =
  240.        (long int *) malloc(num * sizeof(long int))) == NULL)
  241.        return(-1);
  242.        }
  243.     }
  244. return(0);
  245. }
  246. CDFstatus CDFWALK_open(CDF, variables, data_values)
  247. struct        CDF_struct    *CDF;
  248. struct        variable_struct **variables;
  249. union         mixed        **data_values;
  250. {
  251. CDFstatus        rcode;
  252. long int        i,j;
  253. long int        var_num;
  254. /*long int        attr_num;*/
  255. long int        dim_num;
  256. long int        num_true;
  257. /*long int        len;*/
  258. char            temp[CDF_VAR_NAME_LEN];
  259.  
  260. /*
  261. Open the CDF
  262. */
  263. rcode = CDFopen(C.CDF_name, &C.CDF_id);
  264. if(rcode < CDF_OK)return (rcode);
  265.  
  266. rcode = CDFdoc(C.CDF_id, &C.version, &C.release, C.text);
  267.  
  268. for(i=0; i<CDF_MAX_DIMS; i++)
  269.     C.dim_sizes[i] = FALSE;
  270. /*
  271. Inquire about CDF structure
  272. */
  273. rcode = CDFinquire(C.CDF_id, &C.num_dims, C.dim_sizes, &C.encoding,
  274.     &C.majority, &C.max_record_num, &C.num_vars, &C.num_attrs);
  275. if(rcode < CDF_OK)
  276.    return(rcode);
  277. else if(C.max_record_num < 0)
  278. /*
  279. CDF contains no data, nothing to WALK thru
  280. */
  281.     return(NODATA);
  282. *variables = (struct variable_struct *)
  283.         malloc(C.num_vars * sizeof(struct variable_struct));
  284. if(*variables == NULL)return(BAD_MALLOC);
  285. rcode = alloc_all_dim(&C.all_dim_var_num, C.num_vars, C.num_dims);
  286.  
  287. if(rcode != 0)ExitBAD;
  288. if(C.version == 1)
  289.    {
  290.    C.encoding = HOST_ENCODING;
  291.    C.majority = ROW_MAJOR;
  292.    }
  293. else if(C.encoding != NETWORK_ENCODING)
  294.     C.encoding = HOST_ENCODING;
  295.  
  296. C.num_scalars = 0;
  297. C.EPOCH_var_num = NOTTHERE;
  298. C.first_scalar_var_num = NOTTHERE;
  299. C.record_var_num = NOTTHERE;
  300. /*
  301. Initialize up to number of dimensions + 1 for the record number
  302. */
  303. for(i=0; i<C.num_dims+1; i++)
  304.     {
  305.     C.num_per_dim[i] = 0;
  306.     for(j=0; j<C.num_vars; j++)
  307.         C.all_dim_var_num[i][j] = 0;
  308.     }
  309. /*
  310. Get all the variables in the CDF
  311. */
  312.   for (var_num=0; var_num < C.num_vars; var_num++)
  313.     {
  314.     for(i=0; i<CDF_MAX_DIMS; i++)
  315.     VN.dim_variances[i] = FALSE;
  316.     for(i=0; i<CDFWALK_MAX_VAR_LENGTH; i++)VN.var_mnemonic[i] =  ' ';
  317.     rcode = CDFvarInquire(C.CDF_id, var_num, temp, &VN.data_type,
  318.     &VN.num_bytes, &VN.record_variance, VN.dim_variances);
  319.     if(rcode < CDF_OK)return (rcode);
  320.     else
  321.        {
  322.        strncpy(VN.var_mnemonic, temp, CDFWALK_MAX_VAR_LENGTH);
  323.        VN.var_mnemonic[CDFWALK_MAX_VAR_LENGTH] = '\0';
  324.        VN.var_num = var_num;
  325.        VN.dim_variable = FALSE;
  326.        VN.record_variable = FALSE;
  327.        VN.filter = FALSE;
  328.        VN.scalar = SCALAR;
  329.        VN.bin_value = NULL;
  330.        VN.char_value = NULL;
  331.        num_true=0;
  332. /*
  333. Check for a scalar or dimensionally variant variable
  334. */
  335.        for (i=0; i< C.num_dims; i++)
  336.         {
  337.         if(VN.dim_variances[i] != NOVARY)
  338.            {
  339.            dim_num=i+1;
  340.            num_true++;
  341.            VN.scalar = FALSE;
  342.            }
  343.         }
  344.        if(num_true == 1 && !VN.record_variance)
  345.       {
  346.       C.all_dim_var_num[dim_num][C.num_per_dim[dim_num]++] = var_num;
  347.       VN.dim_num = dim_num;
  348.       VN.num_values=C.dim_sizes[dim_num-1];
  349.       }
  350.       else
  351.       {
  352.       if(!VN.record_variance && num_true > 1)
  353.           VN.dim_num = MULTIPLE;
  354.       else
  355.           VN.dim_num = 0;
  356.       VN.num_values=0;
  357.       }
  358.      }
  359.    if(VN.scalar)
  360.       {
  361.       C.all_dim_var_num[0][C.num_per_dim[0]++] = var_num;
  362.       VN.num_values = C.max_record_num+1;
  363.       }
  364.    }/*var loop*/
  365.  
  366.   *data_values = (union mixed *) malloc(C.num_vars * sizeof(union mixed));
  367.   if(*data_values == NULL)return(BAD_MALLOC);
  368.  
  369. return (rcode);
  370. }
  371. void CDFWALK_load_dim(CDF, variables, DIM_display, dim_num, num_rows)
  372. struct CDF_struct    *CDF;
  373. struct variable_struct    variables[];
  374. struct vid_struct      *DIM_display;
  375. long int        dim_num;
  376. int            *num_rows;
  377. {
  378. long int        i;
  379.  
  380. for(i=0; i<C.num_per_dim[dim_num]; i++)
  381.     {
  382.     DIM_display[i].row = 1;
  383.     DIM_display[i].col = 1;
  384.     strcpy(DIM_display[i].label,
  385.        variables[C.all_dim_var_num[dim_num][i]].var_mnemonic);
  386.     }
  387. *num_rows = C.num_per_dim[dim_num]+ROW_OFFSET > DIM_ROWS ? DIM_ROWS :
  388.         C.num_per_dim[dim_num]+ROW_OFFSET;
  389. }
  390. void CDFWALK_list(screen, CDF, variables, VAR_display, data_values,
  391.         curr_field)
  392. struct    GLOBAL_struct    *screen;
  393. struct    CDF_struct    *CDF;
  394. struct  variable_struct    *variables;
  395. struct vid_struct    *VAR_display;
  396. union   mixed        *data_values;
  397. long int         *curr_field;
  398. {
  399. struct  vid_struct     *DIS_display;
  400. struct  vid_struct     *DIM_display;
  401. long int        var_index = 0;
  402. long int        var_num;
  403. long int        val_num;
  404. long int        num;
  405. /*long int        num_elements;*/
  406. long int        dim_num;
  407. long int        field_num;
  408. long int        col_field;
  409. int            row /*,col*/ ;
  410. int            tcode;
  411. /*long int        found;*/
  412. long int        record_num;
  413. long int        indices[10];
  414. /*long int        yr,mo,da,hr,min,sec,msec;*/
  415. char            buf[7], /*buf2[7],*/ buf3[25];
  416. char            temp[80];
  417. long int        i;
  418. static char        dim_number[] = "1234567890";
  419. static char        record_error_mes[] =
  420. "Record number out of range, valid range is from 1 - ";
  421. static char        indices_error_mes[] =
  422. "Index out of range, valid range is from 1 - ";
  423. static char        input_error_mes[] =
  424. "Error detected in input string ";
  425. static char        noscroll_mes[] =
  426. "All variables are currently displayed on screen";
  427. static char        value_input_mes[] =
  428. "Enter desired value from variable ";
  429. static char        EPOCH_input_mes[] =
  430. "Enter a desired time from the CDF ";
  431. static char        record_input_mes[] =
  432. "Enter record number or a number preceded by +/- to increment or decrement";
  433. static char        indices_input_mes[] =
  434. "Enter index number or a number preceded by +/- to increment or decrement";
  435. static char        record_indices_mes[] =
  436. "Right/Left arrows to move +/- thru records/indices, I = input a record/index";
  437. static char        value_mes[] =
  438. "Right/Left arrows=move +/- thru values,I=input value,CTL-P=select value popup";
  439. static char        load_data_mes[] =
  440. "Loading data from CDF...";
  441. static char        select_begin_mes[] =
  442. "Multiple variables describe ";
  443. static char        select_end_mes[] =
  444. " select one for filtering/display";
  445. static char        no_var_mes[] =
  446. "No variables in CDF describe ";
  447. static char        to_many_mes[] =
  448. "This variable contains too many values to select from popup, select manually";
  449. static char        scan_mes[] =
  450. "Scanning for selected data...";
  451. char            mes[80];
  452. long int        type;
  453. long int        offset;
  454. /*long int        EPOCH;*/
  455. int            dis_rows, dis_cols;
  456. int            dim_rows;
  457. long int        num_bytes;
  458. long int        value;
  459. double            rvalue;
  460. long int        update_keydef;
  461. long int        rcode;
  462. int            len;
  463. static long int        offsets[2] = {  9, 46 };
  464. static long int        lengths[2] = { 24,  6 };
  465. static long int        scolumns[2] = { 33, 52 };
  466.  
  467. create_virtual_display(C.num_dims+1+ROW_OFFSET, WALK_COLUMNS, &S.WALK_vid,
  468.                BORDER, BOLD);
  469. #if !defined(vms)
  470. begin_display_update(S.WALK_vid);
  471. #endif
  472. put_chars(S.WALK_vid, "Record#", 7, 1, 39, ERASE, NORMAL);
  473. /*
  474. Now find  the variables that vary with each dimension and place them on the screen
  475. */
  476. for(dim_num = 0; dim_num < C.num_dims; ++dim_num)
  477.     {
  478.     for(i=0; i<WALK_COLUMNS; i++)temp[i] = ' ';
  479.     strcpy(temp, "Dimension");
  480.     strncpy(temp+9, dim_number+dim_num, 1);
  481.     put_chars(S.WALK_vid, temp, 11, dim_num+2, 36, ERASE, NORMAL);
  482.     }
  483. paste_virtual_display(S.WALK_vid, WALK_ROW_PASTE, WALK_COL_PASTE);
  484. #if !defined(vms)
  485. end_display_update(S.WALK_vid);
  486. #endif
  487. label_border(S.WALK_vid, WALK_label, strlen(WALK_label));
  488. /*
  489. Choose a variable for record and each dimension to be displayed in the
  490. WALK window for each dimension if applicable
  491. */
  492. for(dim_num=0; dim_num<=C.num_dims; dim_num++)
  493.  {
  494.  if(C.num_per_dim[dim_num] > 0)
  495.     {
  496.     num = 1;
  497.     if(C.num_per_dim[dim_num] > 1)
  498.        {
  499.        DIM_display = (struct vid_struct *)
  500.             malloc(C.num_per_dim[dim_num] * sizeof(struct vid_struct));
  501.        CDFWALK_load_dim(CDF, variables, DIM_display, dim_num, &dim_rows);
  502. #ifdef vms
  503.        change_virtual_display(dim_rows, DIM_COLUMNS,
  504.             S.DIM_vid, BORDER, BOLD);
  505. #endif
  506. #if defined(unix) | defined(__MSDOS__)
  507.        change_virtual_display(dim_rows,
  508.              DIM_COLUMNS, &S.DIM_vid, BORDER, BOLD);
  509. #endif
  510.        strcpy(mes, select_begin_mes);
  511.        if(dim_num == 0)
  512.       strcat(mes,"Record Number,");
  513.        else
  514.       {
  515.       strcat(mes,"Dimension ");
  516.       strncpy(mes+38, dim_number+(dim_num-1), 1);
  517.       mes[39] = ',';
  518.       mes[40] = '\0';
  519.       }
  520.        strcat(mes,select_end_mes);
  521.        CDFWALK_put_message(S.MES_vid, mes, NOBELL, NORMAL, NOPAUSE);
  522.  
  523.        CDFWALK_Menu_keydef(screen);
  524.        CDFWALK_select_menu_item(S.DIM_vid,
  525.      S.MES_vid, &num, DIM_display, C.num_per_dim[dim_num],
  526.      dim_rows, DIM_COLUMNS, DIM_ROW_PASTE, DIM_COL_PASTE, MENU, &tcode);
  527.        free(DIM_display);
  528.        } /* num_per_dim > 1 */
  529. /*
  530. Only one variable describes this variable or dimension
  531. */
  532.        if(dim_num != RECORD)
  533.       {
  534.       var_num = C.all_dim_var_num[dim_num][num-1];
  535.       C.dim_var_num[dim_num] = var_num;
  536.       V.dim_variable = TRUE;
  537.       }
  538.        else
  539.       {
  540.       var_num = C.all_dim_var_num[RECORD][num-1];
  541.       C.dim_var_num[RECORD] = var_num;
  542.       V.record_variable = TRUE;
  543.       }
  544.        if(V.num_values <= MAX_VALUES)
  545.        {
  546.        if(V.data_type == CDF_EPOCH)
  547.       {
  548.       if((V.bin_value = (double *)
  549.           malloc(V.num_values * sizeof(double))) == NULL)
  550.           {
  551.           printf("Error allocating EPOCH binary discrete ptr");
  552.           ExitBAD;
  553.           }
  554.       if((V.char_value = (char *)
  555.         malloc(V.num_values*EPOCH_WIDTH)) == NULL)
  556.         {
  557.         printf("Error allocating EPOCH character discrete ptr");
  558.         ExitBAD;
  559.         }
  560. /*
  561. Retrieve EPOCH values from CDF
  562. */
  563.      CDFWALK_get_EPOCH(C.CDF_id, var_num, C.max_record_num,
  564.                V.bin_value, V.char_value);
  565.       }
  566.        else if(V.data_type != CDF_CHAR && V.data_type != CDF_UCHAR)
  567.          {
  568.          if((V.bin_value = (double *)
  569.          malloc(V.num_values * sizeof(double))) == NULL)
  570.          {
  571.          printf("Error allocating binary discrete ptr, %ld %ld ",
  572.             var_num, V.num_values);
  573.          ExitBAD;
  574.          }
  575.          if((V.char_value = (char *)
  576.          malloc(V.num_values*MINMAX_SIZE)) == NULL)
  577.          {
  578.          printf("Error allocating character discrete ptr");
  579.          ExitBAD;
  580.          }
  581. /*
  582. Retrieve binary values from the CDF if variable describes a dimension
  583. */
  584.         CDFWALK_get_discrete(C.CDF_id, dim_num, V.var_num, V.data_type,
  585.                   V.num_values, V.bin_value, V.char_value);
  586.          }
  587.       else
  588.          {
  589.          if((V.char_value = (char *)
  590.          malloc(V.num_values*(V.num_bytes+1))) == NULL)
  591.          {
  592.          printf("Error allocating character discrete ptr");
  593.          ExitBAD;
  594.          }
  595. /*
  596. Retrieve character values from the CDF if variable describes a dimension
  597. */
  598.          CDFWALK_get_discrete_char(C.CDF_id, dim_num, V.var_num,
  599.         V.num_values, V.num_bytes, V.char_value);
  600.          }
  601.        } /* MAX_VALUES?? */
  602.        len = strlen(V.var_mnemonic);
  603.        if(len > CDFWALK_MAX_VAR_LENGTH)len = CDFWALK_MAX_VAR_LENGTH;
  604.        put_chars(S.WALK_vid, V.var_mnemonic, len, dim_num+1,1,NOERASE,NORMAL);
  605.     } /* num_dim > 0 */
  606.  else
  607.     {
  608.     strcpy(mes, no_var_mes);
  609.     if(dim_num == 0)
  610.        strcat(mes,"Record Number ");
  611.     else
  612.        {
  613.        strcat(mes,"Dimension ");
  614.        strncpy(mes+39, dim_number+(dim_num-1), 1);
  615.        mes[40] = '\0';
  616.        }
  617.     CDFWALK_put_message(S.MES_vid, mes, RINGBELL, NORMAL, PAUSE);
  618.     }
  619.     for(i=0; i<80; i++)mes[i] = ' ';
  620.  }/*end dim loop*/
  621.  
  622. CDFWALK_alloc_STRING(variables, C.num_vars, data_values);
  623.  
  624. CDFWALK_put_message(S.MES_vid, load_data_mes, NOBELL, BLINK, NOPAUSE);
  625.  
  626. update_keydef = TRUE;
  627. record_num = 0;
  628. for(dim_num=0; dim_num<C.num_dims; dim_num++)indices[dim_num] = 0;
  629. field_num = 0;
  630. if(C.num_per_dim[0] > 0)
  631.    col_field = 0;
  632. else
  633.    col_field = 1;
  634.  
  635. while(*curr_field == WALK_FIELD)
  636.      {
  637.      sprintf(buf, "%6ld", record_num+1);
  638.      put_chars(S.WALK_vid, buf, strlen(buf), 1, WALK_COLUMNS-5-COL_OFFSET,
  639.         NOERASE, NORMAL);
  640.      for(dim_num=0; dim_num<C.num_dims; dim_num++)
  641.      {
  642.      sprintf(buf, "%6ld", indices[dim_num]+1);
  643.      row = dim_num + 2;
  644.      put_chars(S.WALK_vid,buf, strlen(buf),row, WALK_COLUMNS-5-COL_OFFSET,
  645.         NOERASE, NORMAL);
  646.      }
  647. /*
  648. Retrieve the data for the current record and set of indices
  649. */
  650.      CDFWALK_get_data(CDF, variables, C.num_vars, record_num, indices,
  651.             data_values);
  652. /*
  653. Now display the current set of variables and data
  654. */
  655.      CDFWALK_load_var(screen, CDF, variables, VAR_display, var_index,
  656.         data_values);
  657.  
  658.  
  659.      row = field_num + 1;
  660.      if(col_field == 0)
  661.     CDFWALK_put_message(S.MES_vid, value_mes, NOBELL, NORMAL, NOPAUSE);
  662.      else
  663.     CDFWALK_put_message(S.MES_vid, record_indices_mes, NOBELL, NORMAL,
  664.                     NOPAUSE);
  665.      if(update_keydef)CDFWALK_walk_keydef(screen);
  666.      update_keydef = FALSE;
  667.      set_cursor_abs(S.WALK_vid, row, scolumns[col_field]);
  668.  
  669. #ifdef vms
  670.      read_input(&tcode);
  671. #endif
  672. #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
  673.      read_input(S.WALK_vid, &tcode);
  674. #endif
  675.      switch (tcode)
  676.          {
  677.          case KB_RIGHTARROW:
  678. /*
  679. Increment the record number
  680. */
  681.           if(field_num == 0)
  682.              {
  683.              record_num++;
  684.              if(record_num > C.max_record_num)record_num = 0;
  685.              }
  686.           else
  687. /*
  688. Increment the current dimension indice
  689. */
  690.              {
  691.              indices[field_num-1]++;
  692.              if(indices[field_num-1] ==
  693.             C.dim_sizes[field_num-1])indices[field_num-1]=0;
  694.              }
  695.          break;
  696.          case KB_LEFTARROW:
  697. /*
  698. Decrement the record number
  699. */
  700.           if(field_num == 0)
  701.              {
  702.              record_num--;
  703.              if(record_num < 0)record_num = C.max_record_num;
  704.              }
  705.           else
  706. /*
  707. Decrement the current dimension indice
  708. */
  709.              {
  710.              indices[field_num-1]--;
  711.              if(indices[field_num-1] < 0)
  712.             indices[field_num-1]=C.dim_sizes[field_num-1]-1;
  713.              }
  714.          break;
  715.          case KB_UPARROW:
  716. /*
  717. Move up to record or dimension on the screen
  718. */
  719.            field_num--;
  720.            if(field_num < 0)field_num = C.num_dims;
  721.            if(C.num_per_dim[field_num] == 0)col_field = 1;
  722.          break;
  723.          case KB_DOWNARROW:
  724. /*
  725. Move down to record or dimension on the screen
  726. */
  727.           field_num++;
  728.           if(field_num > C.num_dims)field_num = 0;
  729.           if(C.num_per_dim[field_num] == 0)col_field = 1;
  730.          break;
  731.          case KB_RETURN:
  732.          case KB_PAD_ENTER:
  733.           col_field++;
  734.           if(col_field > 1)
  735.              {
  736.              col_field = 0;
  737.              field_num++;
  738.              if(field_num > C.num_dims)field_num = 0;
  739.              if(C.num_per_dim[field_num] == 0)col_field = 1;
  740.              }
  741.          break;
  742.          case KB_BACKFIELD:
  743.           col_field--;
  744.           if(col_field < 0)
  745.              {
  746.              col_field = 1;
  747.              field_num--;
  748.              if(field_num < 0)field_num = C.num_dims;
  749.              }
  750.           else if(C.num_per_dim[field_num] == 0)
  751.               col_field = 1;
  752.          break;
  753.          case INPUT:
  754.          case input:
  755.           var_num = C.dim_var_num[field_num];
  756. /*
  757. Input a record number or indice
  758. */
  759.           read_display(S.WALK_vid, row, temp);
  760.           strncpy(buf3, temp+offsets[col_field],lengths[col_field]);
  761.           buf3[lengths[col_field]] = '\0';
  762.           CDFWALK_left_justify(buf3);
  763.           if(V.data_type == CDF_EPOCH && col_field == 0)
  764.              label_border(S.WALK_vid, WALK_EPOCH_label,
  765.                        strlen(WALK_EPOCH_label));
  766.           put_chars(S.WALK_vid, buf3, strlen(buf3), row,
  767.             offsets[col_field]+1, NOERASE, REVERSE);
  768.           if(col_field == 0)
  769.              {
  770.           if(V.data_type == CDF_EPOCH)
  771.             strcpy(mes, EPOCH_input_mes);
  772.              else
  773.             {
  774.             strcpy(mes, value_input_mes);
  775.             strcat(mes, V.var_mnemonic);
  776.             }
  777.              CDFWALK_put_message(S.MES_vid, mes, NOBELL, NORMAL,
  778.                              NOPAUSE);
  779.              }
  780.           else
  781.              {
  782.              if(field_num == 0)
  783.             CDFWALK_put_message(S.MES_vid, record_input_mes,
  784.                         NOBELL, NORMAL, NOPAUSE);
  785.              else
  786.             CDFWALK_put_message(S.MES_vid, indices_input_mes,
  787.                         NOBELL, NORMAL, NOPAUSE);
  788.              }
  789.           input_field(S.WALK_vid, buf3,
  790.            row, offsets[col_field]+1, lengths[col_field], &tcode);
  791.           if(col_field == 0)
  792.              {
  793. /*
  794. Input actual value
  795. */
  796.              if(V.data_type != CDF_CHAR && V.data_type != CDF_UCHAR)
  797.             {
  798.             if(V.data_type == CDF_EPOCH)
  799.                rcode = check_epoch(buf3, &rvalue);
  800.             else
  801.                rcode = sscanf(buf3, "%lf", &rvalue);   /*V1.0a*/
  802. /*
  803. Retrieve closest indice
  804. */
  805.  
  806.             if(rcode == 0)
  807.                CDFWALK_put_message(S.MES_vid, input_error_mes,
  808.                 RINGBELL, NORMAL, PAUSE);
  809.             else
  810.                {
  811.                CDFWALK_put_message(S.MES_vid, scan_mes,
  812.                 NOBELL, BLINK, NOPAUSE);
  813.                value = CDFWALK_get_index(C.CDF_id, V.dim_num,
  814.                    V.var_num, rvalue, V.data_type,
  815.                    V.bin_value,    V.num_values);
  816.                }
  817.             }
  818.              else
  819.             {
  820.             CDFWALK_put_message(S.MES_vid, scan_mes,
  821.                 NOBELL, BLINK, NOPAUSE);
  822.             value = CDFWALK_get_index_char(C.CDF_id, V.dim_num,
  823.                 V.var_num, buf3, V.num_bytes, V.char_value,
  824.                 V.num_values);
  825.             }
  826.              type = NORMAL;
  827.              }
  828.           else
  829. /*
  830. Input record number or indice
  831. */
  832.              {
  833.              if(strchr(buf3, '+'))
  834. /*
  835. inputing a + in the first character causes the value to be incremented
  836. by the specified amount
  837. */
  838.               {
  839.               type = INCREMENT;
  840.               offset = 1;
  841.               }
  842.              else if(strchr(buf3, '-'))
  843. /*
  844. inputing a - in the first character causes the value to be incremented
  845. by the specified amount
  846. */
  847.               {
  848.               type = DECREMENT;
  849.               offset = 1;
  850.               }
  851.              else
  852.               {
  853.               type = NORMAL;
  854.               offset = 0;
  855.               }
  856.              rcode = sscanf(buf3+offset,"%ld",&value);
  857.              if(rcode == 0)
  858.             CDFWALK_put_message(S.MES_vid, input_error_mes,
  859.                 RINGBELL, NORMAL, PAUSE);
  860.              } /* col_field = 2 */
  861.              if(rcode)
  862.              {
  863. /*
  864.  Check and make sure that values entered were in range
  865. */
  866.              if(field_num == 0)
  867.             {
  868.             if(type == INCREMENT)
  869.                value = record_num + value;
  870.             else if(type == DECREMENT)
  871.               value = record_num - value;
  872.             else if(col_field == 1)
  873. /*
  874. Decrement because using 1 instead of 0 on output line
  875. */
  876.               value = value - 1;
  877. /*
  878. Check record
  879. */
  880.             if(value >= 0 && value <= C.max_record_num)
  881.                record_num = value;
  882.             else
  883.                {
  884.                strcpy(mes, record_error_mes);
  885.                sprintf(buf, "%6ld", C.max_record_num+1);
  886.                strcat(mes, buf);
  887.                CDFWALK_put_message(S.MES_vid, mes, RINGBELL, NORMAL,
  888.                     NOPAUSE);
  889.                }
  890.             } /* field_num == 0 */
  891.              else
  892.             {
  893.             if(type == INCREMENT)
  894.                 value = indices[field_num-1] + value;
  895.             else if(type == DECREMENT)
  896.                 value = indices[field_num-1] - value;
  897.             else if(col_field == 1)
  898. /*
  899. Decrement because using 1 instead of 0 on output line
  900. */
  901.                 value = value - 1;
  902. /*
  903. Check indice
  904. */
  905.             if(value >= 0 && value <= C.dim_sizes[field_num-1]-1)
  906.                indices[field_num-1]=value;
  907.             else
  908.                {
  909.                strcpy(mes, indices_error_mes);
  910.                sprintf(buf, "%6ld", C.dim_sizes[field_num-1]);
  911.                strcat(mes, buf);
  912.                CDFWALK_put_message(S.MES_vid, mes,
  913.                         RINGBELL, NORMAL, NOPAUSE);
  914.                }
  915.             } /* field_num = 1 */
  916.           }
  917.           CDFWALK_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
  918.           if(V.data_type == CDF_EPOCH && col_field == 0)
  919.              label_border(S.WALK_vid, WALK_label, strlen(WALK_label));
  920.           break;
  921.          case NEWVAR:
  922.          case newvar:
  923.           if(C.num_vars <= CDFWALK_MAX_VARS_SCREEN)
  924.              CDFWALK_put_message(S.MES_vid, noscroll_mes,
  925.                         RINGBELL, NORMAL, PAUSE);
  926.           else
  927. /*
  928. Scroll in a new set page of variables
  929. */
  930.              CDFWALK_scroll_var(screen, CDF, variables, VAR_display,
  931.                 &var_index, data_values, curr_field);
  932.           CDFWALK_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
  933.           update_keydef = TRUE;
  934.           break;
  935.          case KB_CTRL_F:
  936.           CDFWALK_field_menu(screen, curr_field);
  937.           update_keydef = TRUE;
  938.          break;
  939.          case KB_CTRL_P:
  940. /*
  941. Select values from a pop-up if positioned into a value and dimension field
  942. */
  943.              var_num = C.dim_var_num[field_num];
  944.           if(col_field == 0 && V.num_values <= MAX_VALUES)
  945.              {
  946.              DIS_display = (struct vid_struct *)
  947.             malloc(V.num_values * sizeof(struct vid_struct));
  948.              if(DIS_display != NULL)
  949.             {
  950. /*
  951. Load in the values in the virtual display
  952. */
  953.  
  954.  
  955.              if(V.data_type == CDF_EPOCH)
  956.             num_bytes = EPOCH_WIDTH;
  957.              else
  958.             num_bytes =
  959.             V.data_type == CDF_CHAR || V.data_type == CDF_UCHAR ?
  960.                 V.num_bytes+1 : MINMAX_SIZE;
  961.              CDFWALK_load_discrete(V.char_value, V.num_values,
  962.              num_bytes, DIS_display, &dis_rows, &dis_cols);
  963. #ifdef vms
  964.              change_virtual_display(dis_rows, dis_cols,
  965.             S.DIS_vid, BORDER, BOLD);
  966. #endif
  967. #if defined(unix) | defined(__MSDOS__)
  968.              change_virtual_display(dis_rows, dis_cols,
  969.             &S.DIS_vid, BORDER, BOLD);
  970. #endif
  971. /*
  972. Select desired value
  973. */
  974.              CDFWALK_Menu_keydef(screen);
  975.              CDFWALK_select_menu_item(S.DIS_vid,
  976.              S.MES_vid, &val_num, DIS_display,
  977.              V.num_values,  dis_rows, dis_cols,
  978.              DIS_ROW_PASTE, DIS_COL_PASTE, MENU, &tcode);
  979.              if(tcode == KB_RETURN)
  980.             {
  981.             if(field_num == 0)
  982.                record_num = val_num-1;
  983.             else
  984.                indices[field_num-1] = val_num-1;
  985.             }
  986.           free(DIS_display);
  987.           }
  988.           update_keydef = TRUE;
  989.           } /* display null */
  990.            else
  991.           CDFWALK_put_message(S.MES_vid, to_many_mes,
  992.                         RINGBELL, NORMAL, PAUSE);
  993.          break;
  994.          case KB_REDRAW:
  995.           repaint_screen();
  996.          break;
  997.          }
  998.      }
  999.      unpaste_virtual_display(S.WALK_vid);
  1000.      CDFWALK_free_STRING(variables, C.num_vars, data_values);
  1001. }
  1002. void CDFWALK_scroll_var(screen, CDF, variables, VAR_display, var_index,
  1003.             data_values, field_num)
  1004. struct GLOBAL_struct    *screen;
  1005. struct    CDF_struct    *CDF;
  1006. struct variable_struct  *variables;
  1007. struct vid_struct    *VAR_display;
  1008. long int        *var_index;
  1009. union mixed         data_values[];
  1010. long int        *field_num;
  1011. {
  1012. int            tcode;
  1013. static char        scroll_mes[] =
  1014. "Press UP/DOWN arrow key to scroll thru variable list, RETURN when ready";
  1015. #if defined(unix) | defined(__MSDOS__)
  1016. begin_display_update(S.VARSCROLL_vid);
  1017. #endif
  1018. load_vid(S.VARSCROLL_vid, VARSCROLL_display, 0, VARSCROLL_NUM_ELEMENTS,
  1019. NO_label);
  1020. paste_virtual_display(S.VARSCROLL_vid,  VARSCROLL_ROW_PASTE,
  1021.                     VARSCROLL_COL_PASTE);
  1022. #if defined(unix) | defined(__MSDOS__)
  1023. end_display_update(S.VARSCROLL_vid);
  1024. #endif
  1025. CDFWALK_scroll_keydef(screen);
  1026. CDFWALK_put_message(S.MES_vid, scroll_mes, NOBELL, NORMAL, NOPAUSE);
  1027. tcode = NOTTHERE;
  1028. while(tcode != KB_RETURN)
  1029. {
  1030. set_cursor_abs(S.VARSCROLL_vid, 1, 34);
  1031. #ifdef vms
  1032.      read_input(&tcode);
  1033. #endif
  1034. #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
  1035.      read_input(S.VARSCROLL_vid, &tcode);
  1036. #endif
  1037. switch (tcode)
  1038.     {
  1039. /*
  1040. calculate a new starting variable number to display
  1041. */
  1042.     case KB_UPARROW:
  1043.          (*var_index)++;
  1044.          if(*var_index == C.num_vars)*var_index = 0;
  1045.          break;
  1046.     case KB_DOWNARROW:
  1047.          (*var_index)--;
  1048.          if(*var_index < 0)*var_index = C.num_vars-1;
  1049.          break;
  1050.     case PAGEUP:
  1051.     case PAGEup:
  1052.          (*var_index)-=CDFWALK_MAX_VARS_SCREEN;
  1053.          if(*var_index < 0)*var_index = 0;
  1054.          break;
  1055.     case PAGEDOWN:
  1056.     case PAGEdown:
  1057.          (*var_index)+=CDFWALK_MAX_VARS_SCREEN;
  1058.          if(*var_index >= C.num_vars)*var_index = C.num_vars - CDFWALK_MAX_VARS_SCREEN;
  1059.          break;
  1060.     case KB_REDRAW:
  1061.          repaint_screen();
  1062.          break;
  1063.     case KB_CTRL_F:
  1064.          CDFWALK_field_menu(screen, field_num);
  1065.          if(field_num != WALK_FIELD)tcode = KB_RETURN;
  1066.          break;
  1067.     case KB_PAD_ENTER:
  1068.          tcode = KB_RETURN;
  1069.              break;
  1070.     }
  1071. /*
  1072. Display the new page of variables and data
  1073. */
  1074.     CDFWALK_load_var(screen, CDF, variables, VAR_display,
  1075.             *var_index, data_values);
  1076. }
  1077. unpaste_virtual_display(S.VARSCROLL_vid);
  1078. }
  1079. void CDFWALK_print_data(screen, select, VAR_display, field_num, var_num,
  1080.             data_values, walker_only)
  1081. struct GLOBAL_struct    *screen;
  1082. struct variable_struct  select[];
  1083. struct vid_struct    *VAR_display;
  1084. long int        field_num;
  1085. long int        var_num;
  1086. union mixed        data_values[];
  1087. int            walker_only;
  1088. {
  1089. long int        len;
  1090. long int        /*i, */ j;
  1091. double            value;
  1092. char            var_data[15];
  1093. char            dim_data[25];
  1094. CDFstatus        rcode;
  1095. static char        time_error[] = "TIME ERROR     ";
  1096. extern char        *epochString();
  1097.  
  1098.  
  1099.     for(j=0; j<15; j++)var_data[j] = ' ';
  1100.     for(j=0; j<25; j++)dim_data[j] = ' ';
  1101.     if(select[var_num].data_type == CDF_EPOCH)
  1102.      {
  1103.      ep.tSince0 = data_values[var_num].r8;
  1104.      strcpy(dim_data, epochString(&ep));
  1105.      rcode = epochParse(dim_data, &ep);
  1106.      if(rcode)
  1107.         {
  1108.         sprintf(var_data,"%04ld%02ld%02ld%02ld%02ld%02ld",ep.year,
  1109.                              ep.month,
  1110.                              ep.day,
  1111.                              ep.hour,
  1112.                              ep.minute,
  1113.                              ep.second);
  1114.         var_data[14] = '\0';
  1115.         }
  1116.      else
  1117.         strcpy(var_data, time_error);
  1118.      }
  1119.     else if(select[var_num].data_type == CDF_CHAR ||
  1120.         select[var_num].data_type == CDF_UCHAR)
  1121.         {
  1122.         remove_trail(data_values[var_num].string);
  1123.         len = strlen(data_values[var_num].string);
  1124.         if(select[var_num].dim_variable || select[var_num].record_variable)
  1125.            {
  1126. /*
  1127. Variable is the first to vary with a dimension, will be displayed in the
  1128. WALK window
  1129. */
  1130.            if(len > 24)
  1131.           {
  1132. /*
  1133. 24 character limit, truncate
  1134. */
  1135.           strncpy(dim_data, data_values[var_num].string, 22);
  1136.           dim_data[22] = '\0';
  1137.           strcat(dim_data,"..");
  1138.           }
  1139.            else
  1140.           strcpy(dim_data+(24-len), data_values[var_num].string);
  1141.            }
  1142. /*
  1143. Display variable only in VAR window
  1144. */
  1145.         if(len > 14)
  1146.            {
  1147. /*
  1148. 14 character limit, truncate
  1149. */
  1150.            strncpy(var_data, data_values[var_num].string, 12);
  1151.            var_data[12] = '\0';
  1152.            strcat(var_data,"..");
  1153.            }
  1154.         else
  1155.            strcpy(var_data+(14-len), data_values[var_num].string);
  1156.         }
  1157.     else
  1158.     {
  1159.     switch(select[var_num].data_type)
  1160.        {
  1161.        case CDF_REAL4:
  1162.        case CDF_FLOAT:
  1163.         value = (double) data_values[var_num].r4;
  1164.         if(value < -1.e12 || value >  1.e12)
  1165.            sprintf(var_data," %13.6e",value);
  1166.         else
  1167.            sprintf(var_data," %13.*f",precision(value),value);
  1168.         break;
  1169.        case CDF_REAL8:
  1170.        case CDF_DOUBLE:
  1171.         value = data_values[var_num].r8;
  1172.         if(value < -1.e12 || value >  1.e12)
  1173.            sprintf(var_data," %13.6e",value);
  1174.         else
  1175.            sprintf(var_data," %13.*f",precision(value),value);
  1176.         break;
  1177.        case CDF_INT4:
  1178.         sprintf(var_data,"   %11ld",data_values[var_num].i4);
  1179.         break;
  1180.        case CDF_UINT4:
  1181.         sprintf(var_data,"    %10lu",data_values[var_num].ui4);
  1182.         break;
  1183.        case CDF_INT2:
  1184.         sprintf(var_data,"        %6d",data_values[var_num].i2);
  1185.         break;
  1186.        case CDF_UINT2:
  1187.         sprintf(var_data,"        %6u",data_values[var_num].ui2);
  1188.         break;
  1189.        case CDF_BYTE:
  1190.        case CDF_INT1:
  1191.         sprintf(var_data,"          %4d",data_values[var_num].byte);
  1192.         break;
  1193.        case CDF_UINT1:
  1194.         sprintf(var_data,"           %3u",data_values[var_num].ubyte);
  1195.        }
  1196.        if(select[var_num].dim_variable || select[var_num].record_variable)
  1197.           {
  1198.           strncpy(dim_data+10, var_data, 14);
  1199.           dim_data[24] = '\0';
  1200.           }
  1201.     }
  1202. /*
  1203. Now display the data
  1204. */
  1205.        if((select[var_num].dim_variable || select[var_num].record_variable) ||
  1206.       (walker_only))
  1207.       put_chars(S.WALK_vid, dim_data, 24, select[var_num].dim_num+1, 10,
  1208.         NOERASE, NORMAL);
  1209.        if(!walker_only)
  1210.        CDFWALK_put_selection(S.VAR_vid, VAR_display,
  1211.         field_num+(VAR_NUM_ELEMENTS/2), var_data, 14, NORMAL);
  1212. }
  1213. void remove_trail(str)
  1214. char        *str;
  1215. {
  1216. long int    len;
  1217. len = strlen(str);
  1218. str+= len-1;
  1219. while(*str == ' ')str--;
  1220. *(str+1) = '\0';
  1221. }
  1222. void CDFWALK_load_var(screen, CDF, variables, VAR_display, index, data_values)
  1223. struct    GLOBAL_struct    *screen;
  1224. struct    CDF_struct    *CDF;
  1225. struct  variable_struct    *variables;
  1226. struct  vid_struct    *VAR_display;
  1227. long int        index;
  1228. union mixed        data_values[];
  1229. {
  1230. long int        var_num;
  1231. long int        num_elements;
  1232. long int        num;
  1233. long int        dim_num;
  1234. num = 0;
  1235. if(C.num_vars > CDFWALK_MAX_VARS_SCREEN)
  1236.    {
  1237.    for(dim_num = 0; dim_num <= C.num_dims; dim_num++)
  1238.        {
  1239.        if(C.num_per_dim[dim_num] > 0)
  1240.       CDFWALK_print_data(screen, variables, VAR_display, num,
  1241.       C.dim_var_num[dim_num], data_values, TRUE);
  1242.        }
  1243.    }
  1244. num_elements=C.num_vars < VAR_NUM_ELEMENTS/2  ? C.num_vars : VAR_NUM_ELEMENTS/2;
  1245. begin_display_update(S.VAR_vid);
  1246. for(num=0; num < num_elements; num++)
  1247.     {
  1248.     var_num = num+index < C.num_vars ? num+index : num+index - C.num_vars;
  1249.    CDFWALK_put_selection(S.VAR_vid, VAR_display, num,
  1250.     V.var_mnemonic,CDFWALK_MAX_VAR_LENGTH,    NORMAL);
  1251.     CDFWALK_print_data(screen, variables, VAR_display, num, var_num,
  1252.         data_values, FALSE);
  1253.     }
  1254. end_display_update(S.VAR_vid);
  1255. }
  1256. void CDFWALK_get_data(CDF, select, num_select, record_num, indices,
  1257.             data_values)
  1258. struct CDF_struct      *CDF;
  1259. struct variable_struct  select[];
  1260. long int        num_select;
  1261. long int        record_num;
  1262. long int        indices[];
  1263. union  mixed        data_values[];
  1264.  
  1265. {
  1266. long int    i;
  1267.  
  1268. for (i = 0; i < num_select; i++)
  1269.      {
  1270.      switch (select[i].data_type)
  1271.     {
  1272.     case CDF_REAL4:
  1273.     case CDF_FLOAT:
  1274.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  1275.         record_num, indices, &data_values[i].r4);
  1276.          break;
  1277.     case CDF_REAL8:
  1278.     case CDF_DOUBLE:
  1279.     case CDF_EPOCH:
  1280.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  1281.         record_num, indices, &data_values[i].r8);
  1282.          break;
  1283.     case CDF_INT4:
  1284.     case CDF_UINT4:
  1285.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  1286.         record_num, indices, &data_values[i].i4);
  1287.          break;
  1288.     case CDF_INT2:
  1289.     case CDF_UINT2:
  1290.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  1291.         record_num, indices, &data_values[i].i2);
  1292.          break;
  1293.     case CDF_BYTE:
  1294.     case CDF_INT1:
  1295.     case CDF_UINT1:
  1296.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  1297.         record_num, indices, &data_values[i].byte);
  1298.          break;
  1299.     case CDF_CHAR:
  1300.     case CDF_UCHAR:
  1301.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  1302.         record_num, indices, data_values[i].string);
  1303.          data_values[i].string[select[i].num_bytes] = '\0';
  1304.     }
  1305.    }
  1306. }
  1307. void CDFWALK_alloc_STRING(select, num_select, data_values)
  1308. struct variable_struct  select[];
  1309. long int        num_select;
  1310. union  mixed        data_values[];
  1311. {
  1312. long int        i;
  1313.  
  1314. for (i = 0; i < num_select; i++)
  1315.      {
  1316.      if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
  1317. /*
  1318. If this is a STRING variable allocate a enough space in the union array
  1319. to hold this variable
  1320. */
  1321.        data_values[i].string = (char *) malloc(select[i].num_bytes+1);
  1322.      }
  1323. }
  1324. void CDFWALK_free_STRING(select, num_select, data_values)
  1325. struct variable_struct  select[];
  1326. long int        num_select;
  1327. union mixed        data_values[];
  1328. {
  1329. long int        i;
  1330. for(i=0; i<num_select; i++)
  1331.     {
  1332.     if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
  1333.        free(data_values[i].string);
  1334.     }
  1335. }
  1336. void CDFWALK_walk_keydef(screen)
  1337. struct            GLOBAL_struct    *screen;
  1338. {
  1339. char            key_line1[KEY_COLUMNS-COL_OFFSET+1];
  1340. char            key_line2[KEY_COLUMNS-COL_OFFSET+1];
  1341. /*
  1342. Load up keypad definitions for selecting a menu item
  1343. */
  1344. key_line1[0] = '\0';
  1345. key_line2[0] = '\0';
  1346. strcat(key_line1,CNTRLM); strcat(key_line1, UP); strcat(key_line1, LEFTW);
  1347. strcat(key_line1,Ides); strcat(key_line1, FORWARD);
  1348. strcat(key_line2,CNTRLW);strcat(key_line2, DOWN); strcat(key_line2, RIGHTW);
  1349. strcat(key_line2,Vdes); strcat(key_line2, BACKWARD);
  1350. CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
  1351. }
  1352. void CDFWALK_Menu_keydef(screen)
  1353. struct            GLOBAL_struct    *screen;
  1354. {
  1355. char            key_line1[KEY_COLUMNS-COL_OFFSET+1];
  1356. char            key_line2[KEY_COLUMNS-COL_OFFSET+1];
  1357. /*
  1358. Load up keypad definitions for selecting a menu item
  1359. */
  1360. key_line1[0] = '\0';
  1361. key_line2[0] = '\0';
  1362. strcat(key_line1,CNTRLM);  strcat(key_line1, UP);
  1363. strcat(key_line1,PUP);strcat(key_line1,RET);strcat(key_line1, Qdes);
  1364. strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);
  1365. strcat(key_line2,PDOWN);strcat(key_line2,HLP);
  1366. CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
  1367. }
  1368. void CDFWALK_scroll_keydef(screen)
  1369. struct            GLOBAL_struct    *screen;
  1370. {
  1371. char            key_line1[KEY_COLUMNS-COL_OFFSET+1];
  1372. char            key_line2[KEY_COLUMNS-COL_OFFSET+1];
  1373. /*
  1374. Load up keypad definitions for selecting a menu item
  1375. */
  1376. key_line1[0] = '\0';
  1377. key_line2[0] = '\0';
  1378. strcat(key_line1,CNTRLM); strcat(key_line1,RET); strcat(key_line1, UP);
  1379. strcat(key_line1,PUP);
  1380. strcat(key_line2,CNTRLW);strcat(key_line2,DEL);strcat(key_line2, DOWN);
  1381. strcat(key_line2,PDOWN);strcat(key_line1, HLP);
  1382. CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
  1383. }
  1384. int init_var_display(display)
  1385. struct    vid_struct     **display;
  1386. {
  1387. long int        i;
  1388. int             row;
  1389. int            col_index;
  1390. static int        cols[] = { 2, 27, 52, 11, 36, 61 };
  1391. row = 1;
  1392. col_index = 0;
  1393. *display = (struct vid_struct *)
  1394.         malloc(VAR_NUM_ELEMENTS * sizeof(struct vid_struct));
  1395. if(*display == NULL)return(BAD_MALLOC);
  1396.  
  1397. for(i=0; i<VAR_NUM_ELEMENTS; i++)
  1398.     {
  1399.     (*display)[i].row = row;
  1400.     (*display)[i].col = cols[col_index];
  1401.     (*display)[i].label[0] = '\0';
  1402.     if(row == 9)
  1403.        {
  1404.        row = 1;
  1405.        col_index++;
  1406.        }
  1407.     else
  1408.        row++;
  1409.     }
  1410. return(0);
  1411. }
  1412.